(function(c) {
    var b = mobiscroll,
        a = b.$,
        f = b.util,
        g = f.isNumeric,
        e = function() {},
        d = b.classes;
    d.Numpad = function(m, B, D) {
        var l, o, r, j, e, p, h, y, x, k, s, n = a(m),
            b = this,
            v = [],
            f = [],
            i = {},
            w = {},
            t = {
                48: 0,
                49: 1,
                50: 2,
                51: 3,
                52: 4,
                53: 5,
                54: 6,
                55: 7,
                56: 8,
                57: 9,
                96: 0,
                97: 1,
                98: 2,
                99: 3,
                100: 4,
                101: 5,
                102: 6,
                103: 7,
                104: 8,
                105: 9
            };

        function q(f) {
            var c, d = e.validate.call(m, {
                    values: h.slice(0),
                    variables: i
                }, b) || [],
                g = d && d.disabled || [];
            b._isValid = d.invalid ? false : true;
            b._tempValue = e.formatValue.call(m, h.slice(0), i, b);
            j = h.length;
            y = d.length || k;
            if (b._isVisible && mobiscroll.running) {
                a('.mbsc-np-ph', l).each(function(b) {
                    a(this).html(e.fill == 'ltr' ? b >= j ? r : p || h[b] : b >= k - y ? b + j < k ? r : p || h[b + j - k] : '');
                });
                a('.mbsc-np-cph', l).each(function() {
                    a(this).html(i[a(this).attr('data-var')] || a(this).attr('data-ph'));
                });
                if (j === k) {
                    for (c = 0; c <= 9; c++) {
                        g.push(c);
                    }
                }
                a('.mbsc-np-btn', l).removeClass(o);
                for (c = 0; c < g.length; c++) {
                    a('.mbsc-np-btn[data-val="' + g[c] + '"]', l).addClass(o);
                }
                if (b._isValid) {
                    a('.mbsc-fr-btn-s .mbsc-fr-btn', l).removeClass(o);
                } else {
                    a('.mbsc-fr-btn-s .mbsc-fr-btn', l).addClass(o);
                }
                if (b.live) {
                    b._hasValue = f || b._hasValue;
                    u(f, false, f);
                    if (f) {
                        x('onSet', {
                            valueText: b._value
                        });
                    }
                }
            }
        }

        function u(d, e, c, g) {
            if (e) {
                q();
            }
            if (!g) {
                s = h.slice(0);
                w = a.extend({}, i);
                v = f.slice(0);
                b._value = b._hasValue ? b._tempValue : null;
            }
            if (d) {
                if (b._isInput) {
                    n.val(b._hasValue && b._isValid ? b._value : '');
                }
                x('onFill', {
                    valueText: b._hasValue ? b._tempValue : '',
                    change: c
                });
                if (c) {
                    b._preventChange = true;
                    n.trigger('change');
                }
            }
        }

        function C(e) {
            var a, c, b = e || [],
                d = [];
            f = [];
            i = {};
            for (a = 0; a < b.length; a++) {
                if (/:/.test(b[a])) {
                    c = b[a].split(':');
                    i[c[0]] = c[1];
                    f.push(c[0]);
                } else {
                    d.push(b[a]);
                    f.push('digit');
                }
            }
            return d;
        }

        function z(a, b) {
            if (!j && !b && !e.allowLeadingZero || a.hasClass('mbsc-fr-btn-d') || a.hasClass('mbsc-np-btn-empty')) {
                return;
            }
            if (j < k) {
                f.push('digit');
                h.push(b);
                q(true);
            }
        }

        function E(e, b) {
            var a, c, d = e.attr('data-var');
            if (!e.hasClass('mbsc-fr-btn-d')) {
                if (d) {
                    c = d.split(':');
                    f.push(c[0]);
                    i[c[0]] = c[1];
                }
                if (b.length + j <= y) {
                    for (a = 0; a < b.length; ++a) {
                        f.push('digit');
                        h.push(g(b[a]) ? +b[a] : b[a]);
                    }
                }
                q(true);
            }
        }

        function A() {
            var b, c, a = f.pop();
            if (j || a !== 'digit') {
                if (a !== 'digit' && i[a]) {
                    delete i[a];
                    c = f.slice(0);
                    f = [];
                    for (b = 0; b < c.length; b++) {
                        if (c[b] !== a) {
                            f.push(c[b]);
                        }
                    }
                } else {
                    h.pop();
                }
                q(true);
            }
        }
        d.Frame.call(this, m, B, true);
        b.setVal = b._setVal = function(d, f, g, i) {
            b._hasValue = d !== null && d !== c;
            h = C(a.isArray(d) ? d.slice(0) : e.parseValue.call(m, d, b));
            u(f, true, g === c ? f : g, i);
        };
        b.getVal = b._getVal = function(a) {
            return b._hasValue || a ? b[a ? '_tempValue' : '_value'] : null;
        };
        b.setArrayVal = b.setVal;
        b.getArrayVal = function(a) {
            return a ? h.slice(0) : b._hasValue ? s.slice(0) : null;
        };
        b._readValue = function() {
            var a = n.val() || '';
            if (a !== '') {
                b._hasValue = true;
            }
            if (p) {
                i = {};
                f = [];
                h = [];
            } else {
                i = b._hasValue ? w : {};
                f = b._hasValue ? v : [];
                h = b._hasValue && s ? s.slice(0) : C(e.parseValue.call(m, a, b));
                u(false, true);
            }
        };
        b._fillValue = function() {
            b._hasValue = true;
            u(true, false, true);
        };
        b._generateContent = function() {
            var g, h, d, c = 1,
                f = '',
                a = '';
            a += '<div class="mbsc-np-hdr"><div role="button" tabindex="0" aria-label="' + e.deleteText + '" class="mbsc-np-del mbsc-fr-btn-e mbsc-ic mbsc-ic-' + e.deleteIcon + '"></div><div class="mbsc-np-dsp">';
            f = e.template.replace(/d/g, '<span class="mbsc-np-ph">' + r + '</span>').replace(/&#100;/g, 'd');
            f = f.replace(/{([a-zA-Z0-9]*)\:?([a-zA-Z0-9\-\_]*)}/g, '<span class="mbsc-np-cph" data-var="$1" data-ph="$2">$2</span>');
            a += f;
            a += '</div></div>';
            a += '<div class="mbsc-np-tbl-c mbsc-w-p"><div class="mbsc-np-tbl">';
            for (g = 0; g < 4; g++) {
                a += '<div class="mbsc-np-row">';
                for (h = 0; h < 3; h++) {
                    d = c;
                    if (c == 10 || c == 12) {
                        d = '';
                    } else if (c == 11) {
                        d = 0;
                    }
                    if (d === '') {
                        if (c == 10 && e.leftKey) {
                            a += '<div role="button" tabindex="0" class="mbsc-np-btn mbsc-np-btn-custom mbsc-fr-btn-e" ' + (e.leftKey.variable ? 'data-var="' + e.leftKey.variable + '"' : '') + ' data-val="' + (e.leftKey.value || '') + '" >' + e.leftKey.text + '</div>';
                        } else if (c == 12 && e.rightKey) {
                            a += '<div role="button" tabindex="0" class="mbsc-np-btn mbsc-np-btn-custom mbsc-fr-btn-e" ' + (e.rightKey.variable ? 'data-var="' + e.rightKey.variable + '"' : '') + ' data-val="' + (e.rightKey.value || '') + '" >' + e.rightKey.text + '</div>';
                        } else {
                            a += '<div class="mbsc-np-btn mbsc-np-btn-empty"></div>';
                        }
                    } else {
                        a += '<div tabindex="0" role="button" class="mbsc-np-btn mbsc-fr-btn-e" data-val="' + d + '">' + d + '</div>';
                    }
                    c++;
                }
                a += '</div>';
            }
            a += '</div></div>';
            return a;
        };
        b._markupReady = function() {
            l = b._markup;
            q();
        };
        b._attachEvents = function(d) {
            d.on('keydown', function(b) {
                if (t[b.keyCode] !== c) {
                    z(a('.mbsc-np-btn[data-val="' + t[b.keyCode] + '"]'), t[b.keyCode]);
                } else if (b.keyCode == 8) {
                    b.preventDefault();
                    A();
                }
            });
            b.tap(a('.mbsc-np-btn', d), function() {
                var b = a(this);
                if (b.hasClass('mbsc-np-btn-custom')) {
                    E(b, b.attr('data-val'));
                } else {
                    z(b, +b.attr('data-val'));
                }
            }, c, 30);
            b.tap(a('.mbsc-np-del', d), A, c, 30);
        };
        b._processSettings = function() {
            e = b.settings;
            e.headerText = (e.headerText || '').replace('{value}', '');
            e.cssClass = (e.cssClass || '') + ' mbsc-np';
            e.template = e.template.replace(/\\d/, '&#100;');
            r = e.placeholder;
            k = (e.template.match(/d/g) || []).length;
            o = 'mbsc-fr-btn-d ' + (e.disabledClass || '');
            p = e.mask;
            x = b.trigger;
            if (p && n.is('input')) {
                n.attr('type', 'password');
            }
        };
        b._indexOf = function(b, c) {
            var a;
            for (a = 0; a < b.length; ++a) {
                if (b[a].toString() === c.toString()) {
                    return a;
                }
            }
            return -1;
        };
        if (!D) {
            b.init(B);
        }
    };
    d.Numpad.prototype = {
        _hasDef: true,
        _hasTheme: true,
        _hasLang: true,
        _hasPreset: true,
        _class: 'numpad',
        _defaults: a.extend({}, d.Frame.prototype._defaults, {
            template: 'dd.dd',
            placeholder: '0',
            deleteIcon: 'backspace',
            allowLeadingZero: false,
            fill: 'rtl',
            deleteText: 'Delete',
            decimalSeparator: '.',
            thousandsSeparator: ',',
            validate: e,
            parseValue: e,
            formatValue: function(j, l, k) {
                var c, e = 1,
                    h = k.settings,
                    i = h.placeholder,
                    f = h.template,
                    g = j.length,
                    d = f.length,
                    b = '';
                for (c = 0; c < d; c++) {
                    if (f[d - c - 1] == 'd') {
                        if (e <= g) {
                            b = j[g - e] + b;
                        } else {
                            b = i + b;
                        }
                        e++;
                    } else {
                        b = f[d - c - 1] + b;
                    }
                }
                a.each(l, function(a, c) {
                    b = b.replace('{' + a + '}', c);
                });
                return a('<div>' + b + '</div>').text();
            }
        })
    };
    b.themes.numpad = b.themes.frame;
    b.presetShort('numpad', 'Numpad', false);
}());


(function() {
    var a = mobiscroll,
        b = a.$,
        c = a.presets.numpad,
        d = {
            min: 0,
            max: 99.99,
            scale: 2,

            prefix: '',
            suffix: '',
            returnAffix: false
        };
    c.decimal = function(e) {
        function f(e) {
            var b, d = e.slice(0),
                a = 0;
            while (d.length) {
                a = a * 10 + d.shift();
            }
            for (b = 0; b < c.scale; b++) {
                a /= 10;
            }
            return a;
        }

        function g(b) {
            var a = f(b).toFixed(c.scale).replace('.', c.decimalSeparator).replace(/\B(?=(\d{3})+(?!\d))/g, c.thousandsSeparator);
            return a;
        }
        var h = b.extend({}, e.settings),
            c = b.extend(e.settings, d, h);
        e.getVal = function(c) {
            var b = e._getVal(c);
            return a.util.isNumeric(b) ? +b : b;
        };
        return {
            template: c.prefix.replace(/d/g, '\\d') + Array((Math.floor(c.max) + '').length + 1).join('d') + (c.scale ? '.' + Array(c.scale + 1).join('d') : '') + c.suffix.replace(/d/g, '\\d'),
            parseValue: function(f) {
                var b, a, d = f || c.defaultValue,
                    e = [];
                if (d) {
                    d = d + '';
                    a = d.match(/\d+\.?\d*/g);
                    if (a) {
                        a = (+a[0]).toFixed(c.scale);
                        for (b = 0; b < a.length; b++) {
                            if (a[b] != '.') {
                                if (+a[b]) {
                                    e.push(+a[b]);
                                } else if (e.length) {
                                    e.push(0);
                                }
                            }
                        }
                    }
                }
                return e;
            },
            formatValue: function(b) {
                var a = g(b);
                return c.returnAffix ? c.prefix + a + c.suffix : a;
            },
            validate: function(j) {
                var a = j.values,
                    i = g(a),
                    d = f(a),
                    h = [];
                if (!a.length && !c.allowLeadingZero) {
                    h.push(0);
                }
                if (e.isVisible()) {
                    b('.mbsc-np-dsp', e._markup).html(c.prefix + i + c.suffix);
                }
                return {
                    disabled: h,
                    invalid: d > c.max || d < c.min || (c.invalid ? e._indexOf(c.invalid, d) != -1 : false)
                };
            }
        };
    };
}());
(function() {
    function c(d) {
        var a = 0,
            b = 1,
            c = 0;
        while (d.length) {
            if (a > 3) {
                b = 60 * 60;
            } else if (a > 1) {
                b = 60;
            }
            c = c + d.pop() * b * (a % 2 ? 10 : 1);
            a++;
        }
        return c;
    }
    var b = mobiscroll,
        a = b.$,
        e = b.presets.numpad,
        d = ['h', 'm', 's'],
        f = {
            min: 0,
            max: 362439,
            defaultValue: 0,
            hourTextShort: 'h',
            minuteTextShort: 'm',
            secTextShort: 's'
        };
    e.timespan = function(g) {
        var k = a.extend({}, g.settings),
            e = a.extend(g.settings, f, k),
            i = {
                h: e.hourTextShort.replace(/d/g, '\\d'),
                m: e.minuteTextShort.replace(/d/g, '\\d'),
                s: e.secTextShort.replace(/d/g, '\\d')
            },
            h = 'd<span class="mbsc-np-sup mbsc-np-time">' + i.s + '</span>';

        function j(f) {
            var c, b = '',
                e = 60 * 60;
            a(d).each(function(d, a) {
                c = Math.floor(f / e);
                f -= c * e;
                e /= 60;
                if (c > 0 || a == 's' && !b) {
                    b = b + (b ? ' ' : '') + c + i[a];
                }
            });
            return b;

        }
        if (e.max > 9) {
            h = 'd' + h;
        }
        if (e.max > 99) {
            h = '<span class="mbsc-np-ts-m">' + (e.max > 639 ? 'd' : '') + 'd</span><span class="mbsc-np-sup mbsc-np-time">' + i.m + '</span>' + h;
        }
        if (e.max > 6039) {
            h = '<span class="mbsc-np-ts-h">' + (e.max > 38439 ? 'd' : '') + 'd</span><span class="mbsc-np-sup mbsc-np-time">' + i.h + '</span>' + h;
        }
        g.setVal = function(a, c, d, e) {
            if (b.util.isNumeric(a)) {
                a = j(a);
            }
            return g._setVal(a, c, d, e);
        };
        g.getVal = function(a) {
            return g._hasValue || a ? c(g.getArrayVal(a)) : null;
        };
        return {
            template: h,
            parseValue: function(g) {
                var c, f = g || j(e.defaultValue),
                    b = [];
                if (f) {
                    a(d).each(function(d, a) {
                        c = new RegExp('(\\d+)' + i[a], 'gi').exec(f);
                        if (c) {
                            c = +c[1];
                            if (c > 9) {
                                b.push(Math.floor(c / 10));
                                b.push(c % 10);
                            } else {
                                if (b.length) {
                                    b.push(0);
                                }
                                if (c || b.length) {
                                    b.push(c);
                                }
                            }
                        } else if (b.length) {
                            b.push(0);
                            b.push(0);
                        }
                    });
                }
                return b;
            },
            formatValue: function(a) {
                return j(c(a));
            },
            validate: function(f) {
                var b = f.values,
                    a = c(b.slice(0)),
                    d = [];
                if (!b.length) {
                    d.push(0);
                }
                return {
                    disabled: d,
                    invalid: a > e.max || a < e.min || (e.invalid ? g._indexOf(e.invalid, +a) != -1 : false)
                };
            }
        };
    };
}());
(function() {
    var b = mobiscroll,
        a = b.$,
        c = b.presets.numpad,
        d = {
            timeFormat: 'hh:ii A',
            amText: 'am',
            pmText: 'pm'
        };
    c.time = function(o) {
        var p = a.extend({}, o.settings),
            b = a.extend(o.settings, d, p),
            j = b.timeFormat.split(':'),
            c = b.timeFormat.match(/a/i),
            m = c ? c[0] == 'a' ? b.amText : b.amText.toUpperCase() : '',
            l = c ? c[0] == 'a' ? b.pmText : b.pmText.toUpperCase() : '',
            n = 0,
            e = b.min ? '' + b.min.getHours() : '',
            f = b.max ? '' + b.max.getHours() : '',
            k = b.min ? '' + (b.min.getMinutes() < 10 ? '0' + b.min.getMinutes() : b.min.getMinutes()) : '',
            g = b.max ? '' + (b.max.getMinutes() < 10 ? '0' + b.max.getMinutes() : b.max.getMinutes()) : '',
            i = b.min ? '' + (b.min.getSeconds() < 10 ? '0' + b.min.getSeconds() : b.min.getSeconds()) : '',
            h = b.max ? '' + (b.max.getSeconds() < 10 ? '0' + b.max.getSeconds() : b.max.getSeconds()) : '';
        b.min ? b.min.setFullYear(2014, 7, 20) : '';
        b.max ? b.max.setFullYear(2014, 7, 20) : '';

        function q(c, e) {
            var b, d = '';
            for (b = 0; b < c.length; ++b) {
                d += c[b] + (b % 2 == (c.length % 2 == 1 ? 0 : 1) && b != c.length - 1 ? ':' : '');
            }
            a.each(e, function(b, a) {
                d += ' ' + a;
            });
            return d;
        }

        function r(d) {
            var a, o, m, s, t, w, p, q, u, v, l = [],
                r = 2 * j.length;
            n = r;
            if (!d.length) {
                if (c) {
                    l.push(0);
                    l.push(b.leftKey.value);
                }
                l.push(b.rightKey.value);
            }
            if (!c && (r - d.length < 2 || d[0] != 1 && (d[0] > 2 || d[1] > 3) && r - d.length <= 2)) {
                l.push('30');
                l.push('00');
            }
            if ((c ? d[0] > 1 || d[1] > 2 : d[0] != 1 && (d[0] > 2 || d[1] > 3)) && d[0]) {
                d.unshift(0);
                n = r - 1;
            }
            if (d.length == r) {
                for (a = 0; a <= 9; ++a) {
                    l.push(a);
                }
            } else if (d.length == 1 && c && d[0] == 1 || d.length && d.length % 2 === 0 || !c && d[0] == 2 && d[1] > 3 && d.length % 2 == 1) {
                for (a = 6; a <= 9; ++a) {
                    l.push(a);
                }
            }
            u = d[1] !== undefined ? '' + d[0] + d[1] : '';
            v = +g == +(d[3] !== undefined ? '' + d[2] + d[3] : '');
            if (b.invalid) {
                for (a = 0; a < b.invalid.length; ++a) {
                    w = b.invalid[a].getHours();
                    p = b.invalid[a].getMinutes();
                    q = b.invalid[a].getSeconds();
                    if (w == +u) {
                        if (j.length == 2 && (p < 10 ? 0 : +('' + p)[0]) == +d[2]) {
                            l.push(p < 10 ? p : +('' + p)[1]);
                            break;
                        } else if ((q < 10 ? 0 : +('' + q)[0]) == +d[4]) {
                            l.push(q < 10 ? q : +('' + q)[1]);
                            break;
                        }
                    }
                }
            }
            if (b.min || b.max) {
                o = +e == +u;
                m = +f == +u;
                t = m && v;
                s = o && v;
                if (d.length === 0) {
                    for (a = c ? 2 : e > 19 ? e[0] : 3; a <= (e[0] == 1 ? 9 : e[0] - 1); ++a) {
                        l.push(a);
                    }
                    if (e >= 10) {
                        l.push(0);
                        if (e[0] == 2) {
                            for (a = 3; a <= 9; ++a) {
                                l.push(a);
                            }
                        }
                    }
                    if (f && f < 10 || e && e >= 10) {
                        for (a = f && f < 10 ? +f[0] + 1 : 0; a < (e && e >= 10 ? e[0] : 10); ++a) {
                            l.push(a);
                        }
                    }
                }
                if (d.length == 1) {
                    if (d[0] === 0) {
                        for (a = 0; a < e[0]; ++a) {
                            l.push(a);
                        }
                    }
                    if (e && (d[0] !== 0 && (c ? d[0] == 1 : d[0] == 2))) {
                        for (a = c ? 3 : 4; a <= 9; ++a) {
                            l.push(a);
                        }
                    }
                    if (d[0] == e[0]) {
                        for (a = 0; a < e[1]; ++a) {
                            l.push(a);
                        }
                    }
                    if (d[0] == f[0] && !c) {
                        for (a = +f[1] + 1; a <= 9; ++a) {
                            l.push(a);
                        }
                    }
                }
                if (d.length == 2 && (o || m)) {
                    for (a = m ? +g[0] + 1 : 0; a < (o ? +k[0] : 10); ++a) {
                        l.push(a);
                    }
                }
                if (d.length == 3 && (m && d[2] == g[0] || o && d[2] == k[0])) {
                    for (a = m && d[2] == g[0] ? +g[1] + 1 : 0; a < (o && d[2] == k[0] ? +k[1] : 10); ++a) {
                        l.push(a);
                    }
                }
                if (d.length == 4 && (s || t)) {
                    for (a = t ? +h[0] + 1 : 0; a < (s ? +i[0] : 10); ++a) {
                        l.push(a);
                    }
                }
                if (d.length == 5 && (s && d[4] == i[0] || t && d[4] == h[0])) {
                    for (a = t && d[4] == h[0] ? +h[1] + 1 : 0; a < (s && d[4] == i[0] ? +i[1] : 10); ++a) {
                        l.push(a);
                    }
                }
            }
            return l;
        }
        return {
            placeholder: '-',
            allowLeadingZero: true,
            template: (j.length == 3 ? 'dd:dd:dd' : j.length == 2 ? 'dd:dd' : 'dd') + (c ? '<span class="mbsc-np-sup">{ampm:--}</span>' : ''),
            leftKey: c ? {
                text: m,
                variable: 'ampm:' + m,
                value: '00'
            } : {
                text: ':00',
                value: '00'
            },
            rightKey: c ? {
                text: l,
                variable: 'ampm:' + l,
                value: '00'
            } : {
                text: ':30',
                value: '30'
            },
            parseValue: function(g) {
                var d, e, a = g || b.defaultValue,
                    f = [];
                if (a) {
                    a = a + '';
                    e = a.match(/\d/g);
                    if (e) {
                        for (d = 0; d < e.length; d++) {
                            f.push(+e[d]);
                        }
                    }
                    if (c) {
                        f.push('ampm:' + (a.match(new RegExp(b.pmText, 'gi')) ? l : m));
                    }
                }
                return f;
            },
            formatValue: function(a, b) {
                return q(a, b);
            },
            validate: function(f) {
                var a = f.values,
                    g = f.variables,
                    e = q(a, g),
                    d = a.length >= 3 ? new Date(2014, 7, 20, '' + a[0] + (a.length % 2 === 0 ? a[1] : ''), '' + a[a.length % 2 === 0 ? 2 : 1] + a[a.length % 2 === 0 ? 3 : 2]) : '';
                return {
                    disabled: r(a),
                    length: n,
                    invalid: (c ? !new RegExp('^(0?[1-9]|1[012])(:[0-5]\\d)?(:[0-5][0-9])' + ' (?:' + b.amText + '|' + b.pmText + ')$', 'i').test(e) : !/^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(e)) || (b.invalid ? o._indexOf(b.invalid, d) != -1 : false) || !((b.min ? b.min <= d : true) && (b.max ? d <= b.max : true))
                };
            }
        };
    };
}());
(function() {
    var a = mobiscroll,
        b = a.$,
        c = a.presets.numpad,
        d = {
            dateOrder: 'mdy',
            dateFormat: 'mm/dd/yy',
            delimiter: '/'
        };
    c.date = function(q) {
        var e, f, h, p, k = [],
            s = b.extend({}, q.settings),
            c = b.extend(q.settings, a.util.datetime.defaults, d, s),
            g = c.dateOrder,
            l = c.min ? '' + (c.getMonth(c.min) + 1) : 0,
            m = c.max ? '' + (c.getMonth(c.max) + 1) : 0,
            n = c.min ? '' + c.getDay(c.min) : 0,
            o = c.max ? '' + c.getDay(c.max) : 0,
            j = c.min ? '' + c.getYear(c.min) : 0,
            i = c.max ? '' + c.getYear(c.max) : 0;
        g = g.replace(/y+/gi, 'yyyy');
        g = g.replace(/m+/gi, 'mm');
        g = g.replace(/d+/gi, 'dd');
        e = g.toUpperCase().indexOf('Y');
        f = g.toUpperCase().indexOf('M');
        h = g.toUpperCase().indexOf('D');
        g = '';
        k.push({
            val: e,
            n: 'yyyy'
        }, {
            val: f,
            n: 'mm'
        }, {
            val: h,
            n: 'dd'
        });
        k.sort(function(a, b) {
            return a.val - b.val;
        });
        b.each(k, function(b, a) {
            g += a.n;
        });
        e = g.indexOf('y');
        f = g.indexOf('m');
        h = g.indexOf('d');
        g = '';
        for (p = 0; p < 8; ++p) {
            g += 'd';
            if (p + 1 == e || p + 1 == f || p + 1 == h) {
                g += c.delimiter;
            }
        }

        function t(a) {
            return a % 4 === 0 && a % 100 !== 0 || a % 400 === 0;
        }

        function u(b) {
            var a, g, v, q, r, d = [],
                k = b[e + 3] !== undefined ? '' + b[e] + b[e + 1] + b[e + 2] + b[e + 3] : '',
                p = b[f + 1] !== undefined ? '' + b[f] + b[f + 1] : '',
                s = b[h + 1] !== undefined ? '' + b[h] + b[h + 1] : '',
                x = '' + c.getMaxDayOfMonth(k || 2012, p - 1 || 0),
                w = j === k && +l === +p,
                u = i === k && +m === +p;
            if (c.invalid) {
                for (a = 0; a < c.invalid.length; ++a) {
                    v = c.getYear(c.invalid[a]);
                    q = c.getMonth(c.invalid[a]);
                    r = c.getDay(c.invalid[a]);
                    if (v == +k && q + 1 == +p) {
                        if ((r < 10 ? 0 : +('' + r)[0]) == +b[h]) {
                            d.push(r < 10 ? r : +('' + r)[1]);
                            break;
                        }
                    }
                    if (q + 1 == +p && r == +s) {
                        if (('' + v).substring(0, 3) == '' + b[e] + b[e + 1] + b[e + 2]) {
                            d.push(('' + v)[3]);
                            break;
                        }
                    }
                    if (v == +k && r == +s) {
                        if ((q < 10 ? 0 : +('' + (q + 1))[0]) == +b[f]) {
                            d.push(q < 10 ? q : +('' + (q + 1))[1]);
                            break;
                        }
                    }
                }
            }
            if (s == '31' && (b.length == f || b.length == f + 1)) {
                if (b[f] != 1) {
                    d.push(2, 4, 6, 9, 11);
                } else {
                    d.push(1);
                }
            }
            if (s == '30' && b[f] === 0 && b.length <= f + 1) {
                d.push(2);
            }
            if (b.length == f) {
                for (a = i === k && +m < 10 ? 1 : 2; a <= 9; ++a) {
                    d.push(a);
                }
                if (j === k && +l >= 10) {
                    d.push(0);
                }
            }
            if (b.length == f + 1) {
                if (b[f] == 1) {
                    for (a = i === k ? +m[1] + 1 : 3; a <= 9; ++a) {
                        d.push(a);
                    }
                    if (j == k) {
                        for (a = 0; a < +l[1]; ++a) {
                            d.push(a);
                        }
                    }
                }
                if (b[f] === 0) {
                    d.push(0);
                    if (i === k || j === k) {
                        for (a = i === k ? +s > +o ? +m : +m + 1 : 0; a <= (j === k ? +s < +n ? +l - 1 : +l - 1 : 9); ++a) {
                            d.push(a);
                        }
                    }
                }
            }
            if (b.length == h) {
                for (a = u ? (+o > 10 ? +o[0] : 0) + 1 : +x[0] + 1; a <= 9; ++a) {
                    d.push(a);
                }
                if (w) {
                    for (a = 0; a < (+n < 10 ? 0 : n[0]); ++a) {
                        d.push(a);
                    }
                }
            }
            if (b.length == h + 1) {
                if (b[h] >= 3 || p == '02') {
                    for (a = +x[1] + 1; a <= 9; ++a) {
                        d.push(a);
                    }
                }
                if (u && +o[0] == b[h]) {
                    for (a = +o[1] + 1; a <= 9; ++a) {
                        d.push(a);
                    }
                }
                if (w && n[0] == b[h]) {
                    for (a = 0; a < +n[1]; ++a) {
                        d.push(a);
                    }
                }
                if (b[h] === 0) {
                    d.push(0);
                    if (u || w) {
                        for (a = u ? +o + 1 : 1; a <= (w ? +n - 1 : 9); ++a) {
                            d.push(a);
                        }
                    }
                }
            }
            if (b[e + 2] !== undefined && p == '02' && s == '29') {
                for (g = +('' + b[e] + b[e + 1] + b[e + 2] + 0); g <= +('' + b[e] + b[e + 1] + b[e + 2] + 9); ++g) {
                    d.push(!t(g) ? g % 10 : '');
                }
            }
            if (b.length == e) {
                if (c.min) {
                    for (a = 0; a < +j[0]; ++a) {
                        d.push(a);
                    }
                }
                if (c.max) {
                    for (a = +i[0] + 1; a <= 9; ++a) {
                        d.push(a);
                    }
                }
                d.push(0);
            }
            if (c.min || c.max) {
                for (g = 1; g < 4; ++g) {
                    if (b.length == e + g) {
                        if (b[e + g - 1] == +j[g - 1] && (g == 3 ? b[e + g - 2] == +j[g - 2] : true)) {
                            for (a = 0; a < +j[g] + (g == 3 && b[f + 1] && +l > +p ? 1 : 0); ++a) {
                                d.push(a);
                            }
                        }
                        if (b[e + g - 1] == +i[g - 1] && (g == 3 ? b[e + g - 2] == +i[g - 2] : true)) {
                            for (a = +i[g] + (g == 3 && +m < +p ? 0 : 1); a <= 9; ++a) {
                                d.push(a);
                            }
                        }
                    }
                }
            }
            return d;
        }

        function r(a) {
            return new Date(+('' + a[e] + a[e + 1] + a[e + 2] + a[e + 3]), +('' + a[f] + a[f + 1]) - 1, +('' + a[h] + a[h + 1]));
        }
        q.getVal = function(a) {
            return q._hasValue || a ? r(q.getArrayVal(a)) : null;
        };
        return {
            placeholder: '-',
            fill: 'ltr',
            allowLeadingZero: true,
            template: g,
            parseValue: function(g) {
                var e, b = [],
                    f = g || c.defaultValue,
                    d = a.util.datetime.parseDate(c.dateFormat, f, c);
                if (f) {
                    for (e = 0; e < k.length; ++e) {
                        if (/m/i.test(k[e].n)) {
                            b = b.concat(((c.getMonth(d) < 9 ? '0' : '') + (c.getMonth(d) + 1)).split(''));
                        } else if (/d/i.test(k[e].n)) {
                            b = b.concat(((c.getDay(d) < 10 ? '0' : '') + c.getDay(d)).split(''));
                        } else {
                            b = b.concat((c.getYear(d) + '').split(''));
                        }
                    }
                }
                return b;
            },
            formatValue: function(b) {
                return a.util.datetime.formatDate(c.dateFormat, r(b), c);
            },
            validate: function(d) {
                var b = d.values,
                    a = r(b);
                return {
                    disabled: u(b),
                    invalid: !(a != 'Invalid Date' && (c.min ? c.min <= a : true) && (c.max ? a <= c.max : true)) || (c.invalid ? q._indexOf(c.invalid, a) != -1 : false)
                };
            }
        };
    };
}());